#include <Windows.h>
#include <gl\GL.h>
#include <gl\GLU.h>

void renderCylinder(GLUquadricObj* quad, float* m, float r)
{
	glColor3f(0,1,0);
	glPushMatrix();
		glMultMatrixf(m);
		glTranslatef(-0.1f, 0, 0);
		glRotatef(90,0,1,0);
		glColor3f(0, 0, 0);
		gluCylinder(quad,r,r,0.2,8,1);
	glPopMatrix();
}

void drawFloor(float groundY, float tileSize, int numTiles)
{
	float start_i = -(tileSize * numTiles)/2;
	float start_j = -(tileSize * numTiles)/2;

	for (int i=0; i<numTiles; ++i) {
		for (int j=0; j<numTiles; ++j) {
			if (i%2 == 0) {
				if (j%2 == 0) glColor3f(.5f, .5f, .5f);
				else glColor3f(.8f, .8f, .8f);
			} else {
				if (j%2 == 0) glColor3f(.8f, .8f, .8f);
				else glColor3f(.5f, .5f, .5f);
			}

			glBegin(GL_QUADS);
			{
				glVertex3f(start_i + i*tileSize, groundY, start_j + j*tileSize);
				glVertex3f(start_i + i*tileSize+tileSize, groundY, start_j + j*tileSize);
				glVertex3f(start_i + i*tileSize+tileSize, groundY, start_j + j*tileSize+tileSize);
				glVertex3f(start_i + i*tileSize, groundY, start_j + j*tileSize+tileSize);
			}
			glEnd();
		}
	}
}

void drawBox(float x, float y, float z)
{
	glEnable(GL_COLOR_MATERIAL);
	glBegin(GL_QUADS);
	{
		// front
		glColor3f(1,0,0);
		glVertex3f(-x/2, -y/2, z/2);
		glVertex3f( x/2, -y/2, z/2);
		glVertex3f( x/2,  y/2, z/2);
		glVertex3f(-x/2,  y/2, z/2);
		// back
		glColor3f(0,1,0);
		glVertex3f(-x/2, -y/2, -z/2);
		glVertex3f( x/2, -y/2, -z/2);
		glVertex3f( x/2,  y/2, -z/2);
		glVertex3f(-x/2,  y/2, -z/2);
		// left
		glColor3f(0,0,1);
		glVertex3f(-x/2, -y/2, z/2);
		glVertex3f(-x/2,  y/2, z/2);
		glVertex3f(-x/2,  y/2, -z/2);
		glVertex3f(-x/2, -y/2, -z/2);
		// right
		glColor3f(1,1,0);
		glVertex3f( x/2, -y/2, z/2);
		glVertex3f( x/2,  y/2, z/2);
		glVertex3f( x/2,  y/2, -z/2);
		glVertex3f( x/2, -y/2, -z/2);
		// top
		glColor3f(1,0,1);
		glVertex3f(-x/2,  y/2, z/2);
		glVertex3f( x/2,  y/2, z/2);
		glVertex3f( x/2,  y/2, -z/2);
		glVertex3f(-x/2,  y/2, -z/2);
		// bottom
		glColor3f(0,1,1);
		glVertex3f(-x/2, -y/2, z/2);
		glVertex3f( x/2, -y/2, z/2);
		glVertex3f( x/2, -y/2, -z/2);
		glVertex3f(-x/2, -y/2, -z/2);
	}
	glEnd();
	// reset color
	glColor3f(1.f, 1.f, 1.f);
	glDisable(GL_COLOR_MATERIAL);
}